''
'' Copyright (C) 2006 Ruben Rodriguez a.k.a. cha0s. ---> rubentbstk[AT]gmail.com
''
''	This software is provided 'as-is', without any express or implied warranty. 
''	In no event will the authors be held liable for any damages arising from 
''	the use of this software.
''	
''	Permission is granted to anyone to use this software for any purpose, 
''	including commercial applications, and to alter it and redistribute it 
''	freely, subject to the following restrictions:
''	
''	1. The origin of this software must not be misrepresented; you must not claim 
''	that you wrote the original software. If you use this software in a product, 
''	an acknowledgment in the product documentation would be appreciated but is 
''	not required.
''	
''	2. Altered source versions must be plainly marked as such, and must not be 
''	misrepresented as being the original software.
''	
''	3. This notice may not be removed or altered from any source 
''	distribution. 
''
''	4. Also, your soul. Your soul is mine. :)
''

#ifndef __rawsock_bi__
#define __rawsock_bi__

  #libpath __path__
  #inclib "rawsock"
  
  #ifndef TRUE

    const as integer TRUE = -1

  #endif

  #ifndef FALSE

    const as integer FALSE = 0

  #endif

  #include "crt.bi"

  #ifdef __fb_win32__
  
    #include "winsockets.bi"
    #inclib "user32"
    
  #endif

  #ifdef __fb_linux__
    
    #include "crt/sys/socket.bi"
    #include "crt/sys/select.bi"
    #include "crt/arpa/inet.bi"
    #include "crt/netdb.bi"
    #include "crt/unistd.bi"
    
    #define h_addr h_addr_list[0]
    
  #endif

  namespace sock.raw
    
    enum ERRORCODES
      
      OK
      FAILED_INIT
      FAILED_RESOLVE
      FAILED_CONNECT
      FAILED_REUSE
      FAILED_BIND
      FAILED_LISTEN
      
    end enum
    
    declare function getHostIP( ) as uinteger
    declare function getPeerIP( byval thisSocket as uinteger ) as uinteger
    declare function getIPString( byval ipAddress as uinteger ) as string

    declare function getName( byval thisIP as uinteger ) as string
    
    declare function resolveHost( byref hostName as string ) as uinteger
    
    declare function TCP_ClientSocket( byref toSocket as uinteger, byref serverName as string, byval port as integer ) as integer
    declare function UDP_ClientSocket( byref toSocket as uinteger, byref serverName as string, byval port as integer ) as integer

    declare function TCP_ServerSocket( byref toSocket as uinteger, byval port as integer, byval maxConn as integer = 1 ) as integer
    declare function UDP_ServerSocket( byref toSocket as uinteger, byval port as integer, byval maxConn as integer = 1 ) as integer

     declare function TCP_Listen( byval sock as uinteger ) as uinteger
  	
      declare function TCP_Recieve( byval sock as uinteger, byval dat as any ptr, byval size as integer, byval flag as uinteger = 0 ) as integer
      declare function TCP_Send   ( byval sock as uinteger, byval dat as any ptr, byval size as integer, byval flag as uinteger = 0 ) as integer

     declare function isReadable( byval sock as uinteger ) as integer
	
    declare sub      TCP_Close       ( byref sock as uinteger )
    
    declare function GetError  ( ) as integer
    
    const as integer NOT_AN_IP = -1
      
  end namespace
  
  #define NewSocket socket_
  
#endif '' __rawsock_bi__